# 导包
import time
from appium import webdriver
from appium.options.android import UiAutomator2Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 配置移动端设备信息
des_caps = {
    "platformName": "Android",  # 移动端系统平台
    "platformVersion": "12",  # 平台对应版本
    "deviceName": "mumu",  # 设备名称（可以随便写）
    "appPackage": "com.netease.yanxuan",  # 包名
    "appActivity": ".SplashActivityDefault"  # Activity页面名
}
# 初始化设备配置信息
option = UiAutomator2Options().load_capabilities(des_caps)
# 创建驱动对象
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", options=option)
# driver.install_app(r'C:\Users\14872\Desktop\com.netease.yanxuan_9.0.2.apk')
time.sleep(2)
# driver.find_element(By.XPATH,'//android.widget.Button[@resource-id="com.netease.yanxuan:id/btn_alert_positive"]').click()
# lel= WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,'//android.widget.Button[@resource-id="com.netease.yanxuan:id/btn_alert_positive"]')))
# lel.click()
# 点击同意
driver.find_element(By.XPATH,
                    '//android.widget.Button[@resource-id="com.netease.yanxuan:id/btn_alert_positive"]').click()
time.sleep(3)
# 广告弹窗
lel = WebDriverWait(driver, 10).until(EC.visibility_of_element_located(
    (By.XPATH, '//android.widget.ImageView[@resource-id="com.netease.yanxuan:id/view_bg"]')))
lel.click()
# 个人中心
ele = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//*[@text = "个人"]')))
ele.click()
# 点击其他
ele = WebDriverWait(driver, 10).until(EC.visibility_of_element_located(
    (By.XPATH, '(//android.widget.ImageView[@resource-id="com.netease.yanxuan:id/img_icon"])[2]')))
ele.click()
# 点击其他登录
ele = WebDriverWait(driver, 10).until(EC.visibility_of_element_located(
    (By.XPATH, '//android.widget.TextView[@resource-id="com.netease.yanxuan:id/newOtherLoginTypes"]')))
ele.click()
# 点击协议
ele = WebDriverWait(driver, 10).until(EC.visibility_of_element_located(
    (By.XPATH, '//android.widget.CheckBox[@resource-id="com.netease.yanxuan:id/check_box"]')))
ele.click()
# 点击邮箱登录
ele = WebDriverWait(driver, 10).until(EC.visibility_of_element_located(
    (By.XPATH, '(//android.widget.ImageView[@resource-id="com.netease.yanxuan:id/img_icon"])[4]')))
ele.click()
# 输入账号
ele=WebDriverWait(driver, 10).until(EC.visibility_of_element_located(
    (By.XPATH, '//android.widget.AutoCompleteTextView[@resource-id="com.netease.yanxuan:id/account_edit"]')))
ele.send_keys('l15534969574@163.com')
# 输入密码
ele=WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,'//*[@text="密码"]')))
ele.send_keys('Lgw130186')
# 点击登录
ele=WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,'//android.widget.TextView[@resource-id="com.netease.yanxuan:id/btn_login_content"]')))
ele.click()
elel=WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,'com.netease.yanxuan:id/user_name'))).text
assert '用户' in elel
print(elel)
# 暂停3秒
time.sleep(3)
# 关闭驱动
driver.quit()